<?php

namespace App\Models;

use DateTimeInterface;
use Illuminate\Database\Eloquent\Model;
use Spatie\EloquentSortable\Sortable;
use Spatie\EloquentSortable\SortableTrait;

class Banner extends Model implements Sortable
{
    use SortableTrait;

    public $sortable = [
        'order_column_name' => 'order_n',
        'sort_when_creating' => true,
    ];

    protected $fillable = [
        'remark',
        'image_path',
        'video_path',
        'order_n',
        'enable',
        'type',
    ];

    const IMAGE_TYPE = 'image';
    const VIDEO_TYPE = 'video';

    public static $typeList = [
        self::IMAGE_TYPE => '图片',
        self::VIDEO_TYPE => '视频',
    ];

    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }
}
